package com.augurit.common.base.extmodel.inner;

import com.augurit.common.base.extmodel.base.BaseTreeNode;
import com.augurit.common.base.extmodel.base.ITreeNode;

public class MultiEntityTreeNode<T> extends BaseTreeNode<T> {

	/**
	 * 树节点ID由 Entity类名 + "#" + Entity对象ID 组成，以"#"作分隔
	 */
	public static final String SPLIT_CHAR = "#";

	
	// ****************** 对象属性 ******************
	// 扩展属性
	private String entityName;
	private Long entityId;

	
	// ****************** 静态方法 ******************
	/**
	 * 分解应用树树节点ID并构造AppTreeNodePk对象
	 * @param nodeId 机构人员树树节点ID，由 Entity类名 + "#" + Entity对象ID 组成
	 * @return
	 */
	public static MultiEntityTreeNode build(String nodeId){
		MultiEntityTreeNode result = null;
		
		if(nodeId != null && nodeId.trim().length() > 0){
			if(nodeId.equals(ITreeNode.ROOT_ID)){
				result = new MultiEntityTreeNode();
				result.setId(ITreeNode.ROOT_ID);
				//result.setRoot(true);
				result.setLeaf(false);
			}else{			
				String[] strs = nodeId.split(SPLIT_CHAR);
				
				if(strs != null && strs.length == 2){
					
					String entityName = strs[0];
					Long entityId = Long.valueOf(strs[1]);
					
					result = new MultiEntityTreeNode();
					result.setId(nodeId);
					result.setEntityName(entityName);
					result.setEntityId(entityId);
					//result.setRoot(false);
				}
			}
		}
		
		return result;
	}
	
	/**
	 * 取得机构人员树树节点ID，由 Entity类名 + "#" + Entity对象ID 组成
	 * @param entityName
	 * @param entityId
	 * @return
	 */
	public static String getKey(String entityName, Long entityId){
		String result = "";
		if(entityName != null && entityName.trim().length() > 0 && entityId != null){
			result = entityName + SPLIT_CHAR + entityId;
		}
		return result;
	}

	// ****************** getter和setter方法 ******************
	public String getEntityName() {
		return entityName;
	}
	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}
	public Long getEntityId() {
		return entityId;
	}
	public void setEntityId(Long entityId) {
		this.entityId = entityId;
	}

}
